package com.lian.hope.mapper;

import com.lian.hope.model.po.VolunteerActivities;
import com.lian.hope.model.vo.VolunteerActivitiesVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VolunteerActivitiesMapper {

    @Select("select * from volunteer_activities")
    List<VolunteerActivitiesVO> listVolunteerActivities();

    /**
     * 随机获取五个活动
     *
     * @return
     */
    @Select("SELECT * FROM volunteer_activities ORDER BY RAND() LIMIT 5")
    List<VolunteerActivitiesVO> getRandomVolunteerActivities();

    /**
     * 新增志愿者活动
     *
     * @param volunteerActivitiesDTO
     */
    @Select(
        "insert into volunteer_activities (activity_name, brief, start_time, end_time, address, " +
        " require_volunteers,create_time, activity_desc_html,contact_phone,contact_avatar_url," +
        "contact_nickname,img_url) values " +
        "(#{activityName}," +
        "#{brief},#{startTime},#{endTime},#{address},#{requireVolunteers}," + "#{createTime}," +
        "#{activityDescHtml},#{contactPhone},#{contactAvatarUrl},#{contactNickname},#{imgUrl})")
    void insertVolunteerActivities(VolunteerActivities volunteerActivitiesDTO);

    @Select("update volunteer_activities set  registered_volunteers= registered_volunteers + 1 where id = #{dynamicId}")
    void addVolunteerNum(Long activityId);

    @Select("update volunteer_activities set  registered_volunteers= registered_volunteers - 1 where id = #{dynamicId}")
    void deletedVolunteerNum(Long activityId);

    /**
     * 根据活动id集合获取所有活动
     *
     * @param ids
     * @return
     */
    List<VolunteerActivitiesVO> listVolunteerActivitiesByIds(List<Long> ids);
}
